<template>
  <Layout :gradient = "true">
    <Header>
      <Close @click="handleBack" slot='left' />
    </Header>
    <Content>
      <Banner />

      <h1>报名参会</h1>

      <form @submit="handleSubmit">
        <div class="form-group">
          <div class="form-control-wrap">
            <input type="text" class="form-control" autocomplete="off" placeholder="您的姓名(必填)" v-model="name" />
            <i></i>
          </div>
          <Icon type = 'bianji' />
        </div>
        <div class="form-group">
          <div class="form-control-wrap">
            <input type="text" class="form-control" autocomplete="off" placeholder="手机号码(必填)" v-model="phone" />
            <i></i>
          </div>
          <Icon type = 'bianji' />
        </div>
        <div class="form-group form-group-picker">
          <div class="form-control-wrap">
            <input readonly @click="handleVisibleAreaPicker" type="text" class="form-control" autocomplete="off" placeholder="所在地区(必填)" v-model="areaFormat" />
            <i></i>
          </div>
          <Icon type = 'bianji' />
        </div>
        <div class="form-group">
          <div class="form-control-wrap">
            <input type="text" class="form-control" autocomplete="off" placeholder="医院" v-model="hospital" />
            <i></i>
          </div>
          <Icon type = 'bianji' />
        </div>
        <div class="form-group">
          <div class="form-control-wrap">
            <input type="text" class="form-control" autocomplete="off" placeholder="邮箱" v-model="mail" />
            <i></i>
          </div>
          <Icon type = 'bianji' />
        </div>
        <div class="form-group">
          <div class="form-control-wrap">
            <input type="text" class="form-control" autocomplete="off" placeholder="职称" v-model="position" />
            <i></i>
          </div>
          <Icon type = 'bianji' />
        </div>
        <div class="form-group">
          <div class="form-control-wrap">
            <input type="password" class="form-control" autocomplete="off" placeholder="密码（6位数字）" v-model="password" />
            <i></i>
          </div>
          <Icon type = 'bianji' />
        </div>
        <div class="form-group">
          <div class="form-control-wrap">
            <input type="password" class="form-control" autocomplete="off" placeholder="确认密码" v-model="repassword" />
            <i></i>
          </div>
          <Icon type = 'bianji' />
        </div>
        <div class="form-group-tip">为了方便日后修改和查看报名信息，请填写密码</div>
        <div class="form-group-radio">
          <h2>是否为ICW会员？</h2>
          <div class="form-group-content">
            <label class="inline-radio">
              <input type="radio" v-model="icw" value="1" />
              <span class="inline-radio-fake" >
                <i></i>
                是
              </span>
            </label>
            <label class="inline-radio">
              <input type="radio" v-model="icw" value="0" />
              <span class="inline-radio-fake" >
                <i></i>
                否
              </span>
            </label>
          </div>
        </div>
        <div class="form-group">
          <div class="form-control-wrap">
            <input type="text" class="form-control" autocomplete="off" placeholder="学校" v-model="school" />
            <i></i>
          </div>
          <Icon type = 'bianji' />
        </div>
        <div class="form-group form-group-picker">
          <div class="form-control-wrap">
            <input readonly @click="handleVisibleBoundaryPicker" type="text" class="form-control" autocomplete="off" placeholder="界数" v-model="boundary" />
            <i></i>
          </div>
          <Icon type = 'bianji' />
        </div>
        <div class="form-group-switch">
          <label class="form-radio">
            <input type="radio" value="reserve" v-model="type" />
            <span class="form-radio-fake">
              <i></i>
              酒店预定
            </span>
          </label>
          <label class="form-radio">
            <input type="radio" value="relay" v-model="type" />
            <span class="form-radio-fake">
              <i></i>
              会议接送
            </span>
          </label>
        </div>
        <div class="tip">（注册成功后，如有问题可至个人中心查看修改或取消报名）</div>
      </form>
      <label class="agree">
        <span class="agree-checkbox">
          <input type="checkbox" v-model="agree" /><i></i>
        </span>
        <span class="agree-content">
          <p>同意“<a>护理栈用户注册协议</a>” </p>
          <p class="sub">（提交报名单后您将成为护理栈的注册用户）</p>
        </span>
      </label>
      <Button @click="handleSubmit" plain class="submit" size = 'larget'>我要报名参会</Button>
      <Popup v-model ="visibleAreaPicker" position = 'bottom' >
        <Picker
          show-toolbar
          title="选择所在地区"
          :columns="areaColumns"
          @change="handleAreaChange"
          @cancel="handleAreaCancel"
          @confirm="handleAreaConfirm"
        />
      </Popup>
      <Popup v-model ="visibleBoundaryPicker" position = 'bottom' >
        <Picker
          show-toolbar
          title="选择所届数"
          :columns="boundaryColumns"
          @cancel="handleBoundaryCancel"
          @confirm="handleBoundaryConfirm"
        />
      </Popup>
    </Content>
    <div :class="{ mask: true, active: visibleMask }" @click="handleMaskClick" />
  </Layout>
</template>

<script>

import Layout from '@/component/layout/index.js'
import Close from '@/component/close/index.vue'
import Icon from '@/component/icon/index.vue'
import Banner from '@/component/banner/index.vue'
import { Button, Picker, Toast, Popup } from 'vant'

const {
  Header,
  Content
} = Layout

const citys = {
  '浙江': ['杭州', '宁波', '温州', '嘉兴', '湖州'],
  '福建': ['福州', '厦门', '莆田', '三明', '泉州']
}

export default {

  name: 'index',

  data() {
    return {
      name: '',
      phone: '',
      area: [],
      hospital: '',
      mail: '',
      position: '',
      password: '',
      repassword: '',
      school: '',
      boundary: [],
      type: 'reserve',
      icw: '',
      agree: false,
    
      visibleAreaPicker: false,
      areaColumns: [
        {
          values: Object.keys(citys)
        }, {
          values: citys['浙江']
        }
      ],
    
      visibleBoundaryPicker: false,
      boundaryColumns: ['2011', '2012', '2013', '2014', '2015']
    }
  },

  computed: {
    areaFormat: function () {
      return this.area.join('-')
    },
    boundaryFormat: function () {
      return this.boundary.join('-')
    },
    visibleMask: function () {
      return this.visibleAreaPicker || this.visibleBoundaryPicker
    }
  },

  methods: {
    handleBack: function (e) {
      this.$router.go(-1)
    },
    handleSubmit: function (e) {
      e.preventDefault()
      
      // 验证表单
      const {
        name
      } = this

      if (!name) {
        Toast('请输入姓名')

        return
      }
    },

    handleMaskClick: function () {
      this.visibleAreaPicker = false
      this.visibleBoundaryPicker = false
    },

    handleAreaChange: function (picker, values) {
      picker.setColumnValues(1, citys[values[0]])
    },
    handleVisibleAreaPicker: function () {
      this.visibleAreaPicker = true
    },
    handleAreaCancel: function (value, index) {
      this.visibleAreaPicker = false
    },
    handleAreaConfirm: function (value, index) {
      this.visibleAreaPicker = false
      this.area = value
    },

    handleVisibleBoundaryPicker: function () {
      this.visibleBoundaryPicker = true
    },
    handleBoundaryCancel: function (value, index) {
      this.visibleBoundaryPicker = false
    },
    handleBoundaryConfirm: function (value, index) {
      this.visibleBoundaryPicker = false
      this.boundary = value
    },

  },

  components: {
    Layout,
    Header,
    Content,
    Close,
    Icon,
    Banner,
    Button,
    Close,
    Picker,
    Popup,
  }
}

</script>

<style lang="less" scoped>

@import '../../less/mixin.less';

h1 {
  padding: 0 18px; 
  margin: 22px 0;
  color: #fff;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.2;
}

form {
  background: #fff;
  margin: 0 5px 15px;
  border-radius: 3px;
  padding: 15px 10px 15px 20px;

  .tip {
    font-size: 10px;
    text-align: center;
    line-height: 1.35;
    color: #a2a2a2;
    margin-top: 25px;
  }
}

.form-group {
  display: flex;
  align-items: center;
  margin-bottom: 20px;

  &:last-child {
    margin-top: 0;
  }

  > i {
    margin-left: 5px;
    font-size: 18px;
    color: #0067AC;
    flex-shrink: 0;
  }

  &-picker {
    .form-control-wrap {
      &:after {
        content: '';
        position: absolute;
        right: 5px;
        top: 15px;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 6px solid #737373;
      }
    }    
  }
}

.form-control-wrap {
  flex-grow: 1;
  position: relative;
  border-bottom: 1px solid #ddd;

  i {
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 0;
    transition: width .3s;
    height: 1px;
    background: #44B9E5;
  }
}

.form-control {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  font-size: 13px;
  color: #1a1a1a;
  padding: 9px 0;
  outline: 0;
  -webkit-appearance: none;

  .resetPlaceholder(#666);

  &.active + i,
  &:focus + i {
    width: 100%;
  }
}

.form-group-tip {
  font-size: 10px;
  color: #FFC000;
  margin-top: -15px;
  margin-bottom: 20px;

  &:before {
    content: '*';
    margin-right: 5px;
  }
}

.form-group-switch {
  margin: 25px 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.form-radio {
  margin: 0 12px;
  position: relative;

  input {
    position: absolute;
    clip: rect(1px 1px 1px 1px);

    &:checked ~ .form-radio-fake {
      i {
        &:after {
          opacity: 1;
          visibility: visible;
          transform: scale(1);
        }
      }
    }
  }

  &-fake {
    font-size: 13px;
    color: #626262;

    i {
      background: #1C78B5;
      border: 1px solid #1C78B5;
      border-radius: 2px;
      position: relative;
      width: 18px;
      height: 18px;
      margin-right: 4px;
      display: inline-block;
      vertical-align: -4px;

      &:after {
        content: '';
        position: absolute;
        top: 0;
        right: 1px;
        bottom: 1px;
        visibility: hidden;
        left: 1px;
        background: url('../../asset/img/checkbox.png') no-repeat center center;
        background-size: contain;
        transition: transform .2s;
        opacity: 0;
        transform: scale(0);
      }
    }
  }
}

.form-group-radio {
  margin: 20px 0;
  display: flex;

  h2 {
    margin: 0;
    padding: 0;
    font-weight: normal;
    max-width: 180px;
    font-size: 12px;
    color: #A2A2A2;
    margin-right: 20px;
  } 

  &-content {
    flex-grow: 1;
    display: flex;
  }
}

.inline-radio {
  position: relative;

  input {
    position: absolute;
    clip: rect(1px 1px 1px 1px);

    &:checked ~ .inline-radio-fake i {
      &:after {
        opacity: 1;
        visibility: visible;
        transform: scale(1);
      }
    }
  }

  &-fake {
    font-size: 13px;
    color: #626262;
    margin-right: 15px;

    i {
      display: inline-block;
      width: 16px;
      height: 16px;
      border-radius: 8px;
      border: 1px solid #1c78b5;
      margin-right: 5px;
      vertical-align: -2px;
      position: relative;

      &:after {
        content: '';
        position: absolute;
        width: 10px;
        height: 10px;
        border-radius: 5px;
        top: 2px;
        left: 2px;
        opacity: 0;
        visibility: hidden;
        transform: scale(0);
        background: #1c78b5;
        transition: transform .2s;
      }
    }
  }
}

.agree {
  display: block;
  margin: 15px 0;
  padding: 0 15px;
  display: flex;

  &-checkbox {
    flex-shrink: 0;
    position: relative;
    margin-right: 10px;
    padding-top: 2px;

    input {
      position: absolute;
      clip: rect(1px 1px 1px 1px);

      &:checked ~ i {
        &:after {
          opacity: 1;
          visibility: visible;
          transform: scale(1);
        }
      }
    }

    i {
      display: inline-block;
      width: 16px;
      height: 16px;
      border-radius: 2px;
      background: #fff; 
      position: relative;

      &:after {
        content: '';
        position: absolute;
        top: 1px;
        right: 2px;
        bottom: 1px;
        visibility: hidden;
        left: 1px;
        background: url('../../asset/img/checkbox-dark.png') no-repeat center center;
        background-size: contain;
        transition: transform .2s;
        opacity: 0;
        transform: scale(0);
      }
    }
  }

  &-content {
    flex-grow: 1;
    font-size: 10px;
    color: #fff;

    p {
      margin-bottom: 5px;

      &:last-child {
        margin-bottom: 0;
      }

      &.sub {
        color: #B4DEEB;
        font-size: 9px;
        margin-left: -4px;
      }
    }

    a {
      color: inherit;
      text-decoration: underline;
    }
  }
}

.submit {
  display: block;
  margin: 17px auto 40px;
  padding: 0 18px;
  height: 34px;
  line-height: 32px;
  background: transparent;
  font-size: 14px;
  color: #fff;
  box-shadow:2px 2px 0px 0px rgba(11,2,5,0.1);
}

.picker {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  transform: translate(0, 100%);
  opacity: 0;
  visibility: hidden;
  transition: transform .3s;
  z-index: 100;

  &.active {
    transform: translate(0, 0);
    opacity: 1;
    visibility: visible;
  }
}

.mask {
  transition: all .3s;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  background: rgba(0,0,0,.6);
  visibility: hidden;
  opacity: 0;

  &.active {
    visibility: visible;
    opacity: 1;
  }
}

</style>
